import { user } from '@/store/user.js'
function hasPermission(value, el) {
    if (!Array.isArray(value)) {
        throw new Error(`需要配置权限，例如 v-permission="['getStatistics3,GET']"`)
    }
    let store = user()
    let hasAuth = value.findIndex(v => store.ruleNames.includes(v)) !== -1
    if (!hasAuth && el) {
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}
export default {
    install(app) {
        app.directive("permission", {
            mounted(el, binding) {
                // binding.value 传递过来的值 el节点
                // 我们拿到后端的数据和当前传递的值对比 如果有就展示 没有就把节点删除掉
                hasPermission(binding.value, el)
            }
        })
    }
}